<template>
  <div class="managementPhoto">
    <div class="image" v-for="(item, index) in data.imgUrl" :key="index">
      <img :src="item.imgUrl" alt="" />
      <el-button
        type="danger"
        :icon="Delete"
        circle
        @click="handleDel(item._id)"
      />
    </div>
  </div>
</template>

<script setup>
import { onMounted, reactive,onUpdated } from "vue";
import { Delete } from "@element-plus/icons-vue";
import { useHomeStore } from "@/stores/home";
import { useRouter} from 'vue-router'
import axios from "axios";
import URL from "@/api/url";
const store = useHomeStore();
const router = useRouter()
const data = reactive({
  imgUrl: [],
});
const handleDel = (id) => {
  axios.delete(URL() + `/photo/delPhoto/${id}`).then(item => {
    if (item.data.code === 20000) {
      ElMessage({
        showClose: true,
        message: item.data.message,
        type: "success",
      });
      photo()
    }
  });
};
function photo() {
  axios.get(URL() + "/photo/findPhoto").then((item) => {
    if (item.data.code === 20000) {
      data.imgUrl = item.data.data;
      store.imgUrl = item.data.data
    }
  });
}
onMounted(() => {
  photo();
});
</script>

<style lang="scss" scoped>
.managementPhoto {
  display: flex;
  flex-wrap: wrap;
  .image {
    display: flex;
    flex-flow: column;
    justify-content: center;
    align-items: center;
    img {
      width: 100px;
      height: 100px;
      border-radius: 5px;
      border: 1px solid #000;
      margin: 10px;
    }
  }
}
</style>